/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.se2.meteocal.helper;


import java.sql.Time;
import java.util.Date;


/**
 *
 * @author Ugo
 */
public class DateUtilityMethods {
    
    /**
    * method that return the distance in days between a Date object and the invocation Date
    */
    public static double distanceInDays(Date date,boolean round){
        Long eventTime, slack;
        Date now;
        eventTime = date.getTime();
        now = new Date();
        //now.setHours(0);
        //now.setMinutes(0);
        //now.setSeconds(0);
        slack= eventTime - now.getTime();
        //System.out.println("round:" + Math.round(((double)slack/(double)(24*3600*1000))));
        //System.out.println("not round: "+ (Double) ((double)slack/(double)(24*3600*1000)) );
        if(round)
            return Math.round(((double)slack/(double)(24*3600*1000)));
        else
            return  ((double)slack/(double)(24*3600*1000));
    }
    
     public static double distanceInDaysAccurate(Date date){
        Long eventTime, slack;
        Date now;
        eventTime = date.getTime();
        now = new Date();
        slack= eventTime - now.getTime();
        //System.out.println("round:" + Math.round(((double)slack/(double)(24*3600*1000))));
        //System.out.println("not round: "+ (Double) ((double)slack/(double)(24*3600*1000)) );
        return  ((double)slack/(double)(24*3600*1000));
    }
    
    public static Date DateAndTime(Date day,Time time){
        Date d;
        d = new Date(day.getYear(), day.getMonth(), day.getDate(),time.getHours(), time.getMinutes());
        return d;
    }
    
    public static boolean isOverlapped(Date startDate1, Date endDate1, Date startDate2, Date endDate2) {      
        if(((startDate1.compareTo(endDate2)<0) && endDate1.compareTo(startDate2)>0))
            return true;
        else return false;
      }
    
    public static boolean isInconsistency(Date begin, Date end){
         if( new Time(begin.getHours(), begin.getMinutes(),0).after(new Time(end.getHours(), end.getMinutes(), 0)))
           return true;
        else 
           return false;
    }
    
}
